﻿<%@ Page Language="C#" MasterPageFile="~/default.Master" AutoEventWireup="true" CodeBehind="Books.aspx.cs"
    Inherits="BookNet.WebForm1" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <br />
            <br />
            <table>
                <tr>
                    <td width="100">
                        <h3>
                            My Listings
                        </h3>
                    </td>
                    <td>
                        &nbsp;<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/AddBook.aspx">[Add]</asp:HyperLink>&nbsp;
                        [<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Detail</asp:LinkButton>&nbsp;
                        <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">List</asp:LinkButton>]
                    </td>
                </tr>
            </table>
            <br />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>"
                DeleteCommand="DELETE FROM [app_Books] WHERE [BookID] = @BookID" InsertCommand="INSERT INTO [app_Books] ([BookID], [Seller], [Title], [Description], [Price], [TimeAdded], [CoverImageUrl], [ForLending], [Condition], [ISBN]) VALUES (@BookID, @Seller, @Title, @Description, @Price, @TimeAdded, @CoverImageUrl, @ForLending, @Condition, @ISBN)"
                OnSelecting="SqlDataSource1_Selecting" SelectCommand="SELECT * FROM [app_Books] WHERE ([Seller] = @Seller) ORDER BY [TimeAdded], [Title]"
                UpdateCommand="UPDATE [app_Books] SET [Title] = @Title, [Description] = @Description, [Price] = @Price, [TimeAdded] = @TimeAdded, [CoverImageUrl] = @CoverImageUrl, [ForLending] = @ForLending, [Condition] = @Condition, [ISBN] = @ISBN WHERE [BookID] = @BookID">
                <SelectParameters>
                    <asp:Parameter Name="Seller" Type="Object" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="BookID" Type="Object" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Seller" />
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="Price" Type="Decimal" />
                    <asp:Parameter Name="TimeAdded" Type="DateTime" />
                    <asp:Parameter Name="CoverImageUrl" Type="String" />
                    <asp:Parameter Name="ForLending" Type="Boolean" />
                    <asp:Parameter Name="Condition" Type="String" />
                    <asp:Parameter Name="ISBN" Type="Int64" />
                    <asp:Parameter Name="BookID" Type="Object" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="BookID" Type="Object" />
                    <asp:Parameter Name="Seller" Type="Object" />
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="Price" Type="Decimal" />
                    <asp:Parameter Name="TimeAdded" Type="DateTime" />
                    <asp:Parameter Name="CoverImageUrl" Type="String" />
                    <asp:Parameter Name="ForLending" Type="Boolean" />
                    <asp:Parameter Name="Condition" Type="String" />
                    <asp:Parameter Name="ISBN" Type="Int64" />
                </InsertParameters>
            </asp:SqlDataSource>
            <asp:Panel ID="Panel1" runat="server">
                <asp:ListView ID="ListView1" runat="server" DataKeyNames="BookID" DataSourceID="SqlDataSource1">
                    <ItemTemplate>
                        <table width="700">
                            <tr>
                                <td style="width: 115px; vertical-align:top;">
                                    <a href="BookDetail.aspx?id=<%# Eval("BookID") %>">
                                        <asp:Image ID="Image1" runat="server" AlternateText='<%# Eval("Title") %>' ImageUrl='<%# ChooseImage(Eval("CoverImageUrl").ToString()) %>'
                                            /></a>
                                </td>
                                <td style="width: 585px;">
                                    Title:
                                    <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
                                    <br />
                                    Description:
                                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
                                    <br />
                                    Price:
                                    <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>'></asp:Label>
                                    <br />
                                    Time Added:
                                    <asp:Label ID="TimeAddedLabel" runat="server" Text='<%# Eval("TimeAdded") %>'></asp:Label>
                                    <br />
                                    <asp:CheckBox ID="ForLendingCheckBox" runat="server" Checked='<%# Eval("ForLending") %>'
                                        Enabled="False" Text="For Lending" />
                                    <br />
                                    Condition:
                                    <asp:Label ID="ConditionLabel" runat="server" Text='<%# Eval("Condition") %>'></asp:Label>
                                    <br />
                                    ISBN:
                                    <asp:Label ID="ISBNLabel" runat="server" Text='<%# Eval("ISBN") %>'></asp:Label>
                                    <br />
                                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                    <AlternatingItemTemplate>
                        <table width="700" style="background-color: #CCFFCC;">
                            <tr>
                                <td style="width: 115px; vertical-align:top;">
                                    <a href="BookDetail.aspx?id=<%# Eval("BookID") %>">
                                        <asp:Image ID="Image1" runat="server" AlternateText='<%# Eval("Title") %>' ImageUrl='<%# ChooseImage(Eval("CoverImageUrl").ToString()) %>'
                                              /></a>
                                </td>
                                <td style="width: 585px;">
                                    Title:
                                    <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
                                    <br />
                                    Description:
                                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
                                    <br />
                                    Price:
                                    <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>'></asp:Label>
                                    <br />
                                    Time Added:
                                    <asp:Label ID="TimeAddedLabel" runat="server" Text='<%# Eval("TimeAdded") %>'></asp:Label>
                                    <br />
                                    <asp:CheckBox ID="ForLendingCheckBox" runat="server" Checked='<%# Eval("ForLending") %>'
                                        Enabled="False" Text="ForLending" />
                                    <br />
                                    Condition:
                                    <asp:Label ID="ConditionLabel" runat="server" Text='<%# Eval("Condition") %>'></asp:Label>
                                    <br />
                                    ISBN:
                                    <asp:Label ID="ISBNLabel" runat="server" Text='<%# Eval("ISBN") %>'></asp:Label>
                                    <br />
                                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                                </td>
                            </tr>
                        </table>
                    </AlternatingItemTemplate>
                    <EmptyDataTemplate>
                        No data was returned.
                    </EmptyDataTemplate>
                    <InsertItemTemplate>
                        <li style="list-style-type: none;">BookID:
                            <br />
                            Title:
                            <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
                            <br />
                            Description:
                            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
                            <br />
                            Price:
                            <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' />
                            <br />
                            Time Added:
                            <asp:TextBox ID="TimeAddedTextBox" runat="server" Text='<%# Bind("TimeAdded") %>' />
                            <br />
                            Cover Image Url:
                            <asp:TextBox ID="CoverImageUrlTextBox" runat="server" Text='<%# Bind("CoverImageUrl") %>' />
                            <br />
                            <asp:CheckBox ID="ForLendingCheckBox" runat="server" Checked='<%# Bind("ForLending") %>'
                                Text="ForLending" />
                            <br />
                            Condition:
                            <asp:TextBox ID="ConditionTextBox" runat="server" Text='<%# Bind("Condition") %>' />
                            <br />
                            ISBN:
                            <asp:TextBox ID="ISBNTextBox" runat="server" Text='<%# Bind("ISBN") %>' />
                            <br />
                            <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
                        </li>
                    </InsertItemTemplate>
                    <LayoutTemplate>
                        <div style="text-align: left; background-color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif;
                            color: #000000; width: 700px; padding-left: 0px;">
                            <table id="itemPlaceholderContainer" runat="server" style="font-family: Verdana, Arial, Helvetica, sans-serif;
                                list-style-type: none; width: 600px; padding-left: 0px;">
                                <tr style="background-color: #000000; color: #000000; list-style-type: none; padding-left: 0px;">
                                    <td id="itemPlaceholder" runat="server">
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div style="text-align: left; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
                            color: #000000; width: 700px;">
                            <asp:DataPager ID="DataPager1" runat="server" PageSize="5">
                                <Fields>
                                    <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowLastPageButton="True" />
                                </Fields>
                            </asp:DataPager>
                        </div>
                    </LayoutTemplate>
                    <EditItemTemplate>
                        <li style="background-color: #008A8C; color: #FFFFFF; list-style-type: none;">BookID:
                            Title:
                            <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
                            <br />
                            Description:
                            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
                            <br />
                            Price:
                            <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' />
                            <br />
                            Cover Image Url:
                            <asp:TextBox ID="CoverImageUrlTextBox" runat="server" Text='<%# Bind("CoverImageUrl") %>' />
                            <br />
                            <asp:CheckBox ID="ForLendingCheckBox" runat="server" Checked='<%# Bind("ForLending") %>'
                                Text="ForLending" />
                            <br />
                            Condition:
                            <asp:TextBox ID="ConditionTextBox" runat="server" Text='<%# Bind("Condition") %>' />
                            <br />
                            ISBN:
                            <asp:TextBox ID="ISBNTextBox" runat="server" Text='<%# Bind("ISBN") %>' />
                            <br />
                            <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
                            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
                        </li>
                    </EditItemTemplate>
                    <ItemSeparatorTemplate>
                    </ItemSeparatorTemplate>
                    <SelectedItemTemplate>
                        <li style="background-color: #008A8C; font-weight: bold; color: #FFFFFF; list-style-type: none;">
                            BookID:
                            <asp:Label ID="BookIDLabel" runat="server" Text='<%# Eval("BookID") %>' />
                            <br />
                            Seller:
                            <asp:Label ID="SellerLabel" runat="server" Text='<%# Eval("Seller") %>' />
                            <br />
                            Title:
                            <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
                            <br />
                            Description:
                            <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
                            <br />
                            Price:
                            <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>' />
                            <br />
                            Time Added:
                            <asp:Label ID="TimeAddedLabel" runat="server" Text='<%# Eval("TimeAdded") %>' />
                            <br />
                            Cover Image Url:
                            <asp:Label ID="CoverImageUrlLabel" runat="server" Text='<%# Eval("CoverImageUrl") %>' />
                            <br />
                            <asp:CheckBox ID="ForLendingCheckBox" runat="server" Checked='<%# Eval("ForLending") %>'
                                Enabled="false" Text="ForLending" />
                            <br />
                            Condition:
                            <asp:Label ID="ConditionLabel" runat="server" Text='<%# Eval("Condition") %>' />
                            <br />
                            ISBN:
                            <asp:Label ID="ISBNLabel" runat="server" Text='<%# Eval("ISBN") %>' />
                            <br />
                            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                        </li>
                    </SelectedItemTemplate>
                </asp:ListView>
            </asp:Panel>
            <asp:Panel ID="Panel2" runat="server">
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataKeyNames="BookID" DataSourceID="SqlDataSource2"
                    Width="600px">
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                        <asp:BoundField DataField="TimeAdded" HeaderText="TimeAdded" SortExpression="TimeAdded" />
                        <asp:BoundField DataField="CoverImageUrl" HeaderText="CoverImageUrl" SortExpression="CoverImageUrl" />
                        <asp:CheckBoxField DataField="ForLending" HeaderText="ForLending" SortExpression="ForLending">
                            <ControlStyle Width="10px" />
                        </asp:CheckBoxField>
                        <asp:BoundField DataField="Condition" HeaderText="Condition" SortExpression="Condition" />
                        <asp:BoundField DataField="ISBN" HeaderText="ISBN" SortExpression="ISBN" />
                        <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>"
                    DeleteCommand="DELETE FROM [app_Books] WHERE [BookID] = @BookID" InsertCommand="INSERT INTO [app_Books] ([Seller], [Title], [Description], [Price], [TimeAdded], [CoverImageUrl], [ForLending], [Condition], [ISBN], [Author]) VALUES (@Seller, @Title, @Description, @Price, @TimeAdded, @CoverImageUrl, @ForLending, @Condition, @ISBN, @Author)"
                    OnSelecting="SqlDataSource2_Inserting" SelectCommand="SELECT * FROM [app_Books] WHERE ([Seller] = @Seller) ORDER BY [TimeAdded] DESC, [Title]"
                    UpdateCommand="UPDATE [app_Books] SET [Title] = @Title, [Description] = @Description, [Price] = @Price, [TimeAdded] = @TimeAdded, [CoverImageUrl] = @CoverImageUrl, [ForLending] = @ForLending, [Condition] = @Condition, [ISBN] = @ISBN, [Author] = @Author WHERE [BookID] = @BookID">
                    <SelectParameters>
                        <asp:Parameter Name="Seller" Type="Object" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="BookID" Type="Object" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Seller" />
                        <asp:Parameter Name="Title" Type="String" />
                        <asp:Parameter Name="Description" Type="String" />
                        <asp:Parameter Name="Price" Type="Decimal" />
                        <asp:Parameter Name="TimeAdded" Type="DateTime" />
                        <asp:Parameter Name="CoverImageUrl" Type="String" />
                        <asp:Parameter Name="ForLending" Type="Boolean" />
                        <asp:Parameter Name="Condition" Type="String" />
                        <asp:Parameter Name="ISBN" Type="Int64" />
                        <asp:Parameter Name="Author" Type="String" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter Name="Seller" />
                        <asp:Parameter Name="Title" Type="String" />
                        <asp:Parameter Name="Description" Type="String" />
                        <asp:Parameter Name="Price" Type="Decimal" />
                        <asp:Parameter Name="TimeAdded" Type="DateTime" />
                        <asp:Parameter Name="CoverImageUrl" Type="String" />
                        <asp:Parameter Name="ForLending" Type="Boolean" />
                        <asp:Parameter Name="Condition" Type="String" />
                        <asp:Parameter Name="ISBN" Type="Int64" />
                        <asp:Parameter Name="Author" Type="String" />
                    </InsertParameters>
                </asp:SqlDataSource>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
